<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\DB;
use think\facade\Log;
class Productinfo extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['detail','aboutinfo','getproduct','info','quality', 'app', 'link','apps','app_detail'];
    // 获取产品名称
    public function info(){
        // $userinfo = $this->auth->getUserinfo();
        $limit = $this->request->post('limit');
        if(!$limit){
            $this->error('limit参数不存在');
        }
        $res = DB::name('product_info')->field('id,product_name,icon')->limit($limit)->order('sort desc')->select();
        foreach ($res as $key => &$value) {
            if(!empty($value['icon'])){
                $value['icon'] =  request()->domain() . $value['icon'];
            }
            $value['text_url'] =  request()->domain() . '/admin/product/productinfo/detail/ids/' . $value['id'];
        }
        $this->success('', $res);
    }
    // 获取产品名称对应的信息描述
    public function getproduct(){
        $id = $this->request->post('id');
        if(!$id){
            $this->error('id参数不存在');
        }
        $where['id'] = $id;
        $res = DB::name('product_info')->field('text')->where($where)->find();
        $this->success('', $res['text']);
    }
    // 关于
    public function aboutinfo(){
        // 获取最新的一条
        $res = $res = DB::name('about_info')->field('id,telephone,wechat,qq,version')->order('updatetime desc')->find();
        if(!$res){
            $this->error('查询数据为空');
        }
        $res['text_url'] = request()->domain() . '/admin/product/aboutinfo/detail/ids/' . $res['id'];
        $this->success('', $res);
    }
    /**
     * 详情
     */
    public function detail($ids)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $this->view->assign("row", $row);
        return $this->view->fetch();
    }
}
